﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Web.Security;
using System.Text;
using System.Data;

namespace MidSoft.Finance.Contract
{
    public partial class Show : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.Params["Type"] != null && Request.Params["Type"].Trim() != "")
                {
                    string typeid = Request.Params["Type"];
                    if(Request.Params["ProjectId"]!=null&&Request.Params["ProjectId"]!="")
                    {
                        int projectId=ChinaSoft.Common.Input.SetInt(Request.Params["ProjectId"]);
                        switch (typeid)
                        {
                            case "0"://主合同
                                ShowInfo(projectId, "0");
                                break;
                            case "1"://分包合同
                                ShowInfo(projectId, "1");
                                break;
                        }
                    }
                }
                if (Request.Params["id"] != null && Request.Params["id"] != "")
                {
                    int id = ChinaSoft.Common.Input.SetInt(Request.Params["id"]);
                    ShowInfoByID(id);
                }
            }
        }

        private void ShowInfo(int ProjectInfoId, string ContractType)
        {
            ChinaSoft.BLL.Common.Bind bllBind = new ChinaSoft.BLL.Common.Bind();
            DataSet ds = bllBind.GetDataSet("*", "V_ContractList", " ProjectInfoId=" + ProjectInfoId + " and ContractType='"+ContractType+"'");
            if (ds != null && ds.Tables.Count > 0&&ds.Tables[0].Rows.Count>0)
            {
                DataRow dr = ds.Tables[0].Rows[0];
                this.lblProjectNumber.Text = dr["ProjectNumber"].ToString();
                this.lblContractNumber.Text = dr["ContractNumber"].ToString();
                this.lblProjectInfoName.Text = dr["ProjectName"].ToString();
                this.lblContractName.Text = dr["ContractName"].ToString();
                this.lblUnit.Text =dr["Unit"].ToString();
                this.lblContractMoney.Text =dr["ContractMoney"].ToString();
                this.lblConfirmDate.Text =Convert.ToDateTime(dr["ConfirmDate"].ToString()).ToShortDateString();
                this.lblAddress.Text = dr["Address"].ToString();
                this.hylinkDown.Text = dr["FileName"].ToString();
                if (dr["FileFolder"].ToString()!="")
                    this.hylinkDown.NavigateUrl = "Uploads/" + dr["FileFolder"].ToString() + "/" + dr["FileSaveName"].ToString();
                this.lblContractType.Text = dr["ContractType"].ToString()=="0"?"主合同":"分合同";
                this.lblCreateTime.Text = dr["CreateTime"].ToString();
            }
        }
        private void ShowInfoByID(int ID)
        {
            ChinaSoft.BLL.Common.Bind bllBind = new ChinaSoft.BLL.Common.Bind();
            DataSet ds = bllBind.GetDataSet("*", "V_ContractList", " ContractId=" + ID);
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                DataRow dr = ds.Tables[0].Rows[0];
                this.lblProjectNumber.Text = dr["ProjectNumber"].ToString();
                this.lblContractNumber.Text = dr["ContractNumber"].ToString();
                this.lblProjectInfoName.Text = dr["ProjectName"].ToString();
                this.lblContractName.Text = dr["ContractName"].ToString();
                this.lblUnit.Text = dr["Unit"].ToString();
                this.lblContractMoney.Text = dr["ContractMoney"].ToString();
                this.lblConfirmDate.Text = Convert.ToDateTime(dr["ConfirmDate"].ToString()).ToShortDateString();
                this.lblAddress.Text = dr["Address"].ToString();
                this.hylinkDown.Text = dr["FileName"].ToString();
                if (dr["FileFolder"].ToString() != "")
                    this.hylinkDown.NavigateUrl = "Uploads/" + dr["FileFolder"].ToString() + "/" + dr["FileSaveName"].ToString();
                this.lblContractType.Text = dr["ContractType"].ToString() == "0" ? "主合同" : "分合同";
                this.lblCreateTime.Text = dr["CreateTime"].ToString();
            }
        }
    }
}